<template>
  <el-dialog v-model="visible" :title="!dataForm.id ? $t('add') : $t('update')" :close-on-click-modal="false" :close-on-press-escape="false">
    <el-form :model="dataForm" :rules="dataRule" ref="dataFormRef" @keyup.enter="dataFormSubmitHandle()" label-width="120px">
      <el-form-item label="" prop="id">
        <el-input v-model="dataForm.id" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="用户id" prop="userId">
        <el-input v-model="dataForm.userId" placeholder="用户id"></el-input>
      </el-form-item>
      <el-form-item label="得分" prop="score">
        <el-input v-model="dataForm.score" placeholder="得分"></el-input>
      </el-form-item>
      <el-form-item label="时间" prop="seconds">
        <el-input v-model="dataForm.seconds" placeholder="时间"></el-input>
      </el-form-item>
      <el-form-item label="钻圈(10分)" prop="add1">
        <el-input v-model="dataForm.add1" placeholder="钻圈(10分)"></el-input>
      </el-form-item>
      <el-form-item label="逆时针(10分)" prop="add2">
        <el-input v-model="dataForm.add2" placeholder="逆时针(10分)"></el-input>
      </el-form-item>
      <el-form-item label="绕龙门(20分)" prop="add3">
        <el-input v-model="dataForm.add3" placeholder="绕龙门(20分)"></el-input>
      </el-form-item>
      <el-form-item label="高低圈(30分)" prop="add4">
        <el-input v-model="dataForm.add4" placeholder="高低圈(30分)"></el-input>
      </el-form-item>
      <el-form-item label="蛇形圈(30分)" prop="add5">
        <el-input v-model="dataForm.add5" placeholder="蛇形圈(30分)"></el-input>
      </el-form-item>
      <el-form-item label="停机坪" prop="add6">
        <el-input v-model="dataForm.add6" placeholder="停机坪"></el-input>
      </el-form-item>
      <el-form-item label="备用1" prop="add7">
        <el-input v-model="dataForm.add7" placeholder="备用1"></el-input>
      </el-form-item>
      <el-form-item label="备用2" prop="add8">
        <el-input v-model="dataForm.add8" placeholder="备用2"></el-input>
      </el-form-item>
      <el-form-item label="备用3" prop="add9">
        <el-input v-model="dataForm.add9" placeholder="备用3"></el-input>
      </el-form-item>
      <el-form-item label="备用4" prop="add10">
        <el-input v-model="dataForm.add10" placeholder="备用4"></el-input>
      </el-form-item>
      <el-form-item label="护目镜" prop="sub1">
        <el-input v-model="dataForm.sub1" placeholder="护目镜"></el-input>
      </el-form-item>
      <el-form-item label="触网(5分/次)" prop="sub2">
        <el-input v-model="dataForm.sub2" placeholder="触网(5分/次)"></el-input>
      </el-form-item>
      <el-form-item label="碰人(20分/次)" prop="sub3">
        <el-input v-model="dataForm.sub3" placeholder="碰人(20分/次)"></el-input>
      </el-form-item>
      <el-form-item label="触地(20分/次)" prop="sub4">
        <el-input v-model="dataForm.sub4" placeholder="触地(20分/次)"></el-input>
      </el-form-item>
      <el-form-item label="障碍倒地(10分/次)" prop="sub5">
        <el-input v-model="dataForm.sub5" placeholder="障碍倒地(10分/次)"></el-input>
      </el-form-item>
      <el-form-item label="超高(10分/次)" prop="sub6">
        <el-input v-model="dataForm.sub6" placeholder="超高(10分/次)"></el-input>
      </el-form-item>
      <el-form-item label="出活动区(5分/次)" prop="sub7">
        <el-input v-model="dataForm.sub7" placeholder="出活动区(5分/次)"></el-input>
      </el-form-item>
      <el-form-item label="备用1" prop="sub8">
        <el-input v-model="dataForm.sub8" placeholder="备用1"></el-input>
      </el-form-item>
      <el-form-item label="备用2" prop="sub9">
        <el-input v-model="dataForm.sub9" placeholder="备用2"></el-input>
      </el-form-item>
      <el-form-item label="备用3" prop="sub10">
        <el-input v-model="dataForm.sub10" placeholder="备用3"></el-input>
      </el-form-item>
      <el-form-item label="创建人" prop="creator">
        <el-input v-model="dataForm.creator" placeholder="创建人"></el-input>
      </el-form-item>
      <el-form-item label="创建时间" prop="createDate">
        <el-input v-model="dataForm.createDate" placeholder="创建时间"></el-input>
      </el-form-item>
    </el-form>
    <template v-slot:footer>
      <el-button @click="visible = false">{{ $t("cancel") }}</el-button>
      <el-button type="primary" @click="dataFormSubmitHandle()">{{ $t("confirm") }}</el-button>
    </template>
  </el-dialog>
</template>

<script lang="ts">
import { defineComponent, reactive } from "vue";
import baseService from "@/service/baseService";
import { useDebounce } from "@/utils/utils";
export default defineComponent({
  setup() {
    return reactive({
      visible: false,
      dataForm: {
        id: "",
        userId: "",
        score: "",
        seconds: "",
        add1: "",
        add2: "",
        add3: "",
        add4: "",
        add5: "",
        add6: "",
        add7: "",
        add8: "",
        add9: "",
        add10: "",
        sub1: "",
        sub2: "",
        sub3: "",
        sub4: "",
        sub5: "",
        sub6: "",
        sub7: "",
        sub8: "",
        sub9: "",
        sub10: "",
        creator: "",
        createDate: ""
      }
    });
  },
  computed: {
    dataRule() {
      return {};
    }
  },
  created() {
    this.dataFormSubmitHandle = useDebounce(this.dataFormSubmitHandle);
  },
  methods: {
    init() {
      this.visible = true;
      this.$nextTick(() => {
        this.$refs["dataFormRef"].resetFields();
        if (this.dataForm.id) {
          this.getInfo();
        }
      });
    },
    // 获取信息
    getInfo() {
      baseService.get("/sp/spuserscore/").then((res) => {
        if (res.code !== 0) {
          return this.$message.error(res.msg);
        }
        this.dataForm = res.data;
      });
    },
    // 表单提交
    dataFormSubmitHandle() {
      this.$refs["dataFormRef"].validate((valid: boolean) => {
        if (!valid) {
          return false;
        }
        (!this.dataForm.id ? baseService.post : baseService.put)("/sp/spuserscore", this.dataForm).then((res) => {
          if (res.code !== 0) {
            return this.$message.error(res.msg);
          }
          this.$message({
            message: this.$t("prompt.success"),
            type: "success",
            duration: 500,
            onClose: () => {
              this.visible = false;
              this.$emit("refreshDataList");
            }
          });
        });
      });
    }
  }
});
</script>
